/*
 * RevenueSourceFactory.java
 *
 * Created on March 27, 2007, 10:01 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.samlam;

import java.util.Map;
import java.util.TreeMap;

/**
 * A factory for retrieving the correct DAO based on why type of BusinessObject
 * the user needs to interact with.
 * @author Sam
 */
public class RevenueSourceFactory {
    ///////////////////////////////////////
    ///   Singleton pattern
    
    private static RevenueSourceFactory instance;
    private static Map map = new TreeMap();
    private String[] key = {"sales", "return", "rental", "backup", "print", "conversion"}; 
    private RevenueSourceDAO[] value = {SaleDAO.getInstance(), /*ReturnDAO.getInstance(), RentalDAO.getInstance(),*/ BackupDAO.getInstance(), PrintDAO.getInstance(), ConversionDAO.getInstance()};
    
    /** Creates a new instance of RevenueSourceFactory */
    private RevenueSourceFactory() {
        for(int i = 0 ; i<key.length ; i++){
            map.put(key[i], value[i]);
        }
    }
    
    /**
     * Creates an instance of RevenueSourceFactory if one doesn't already
     * exist 
     * @return returns an instance of RevenueSourceFactory
     */
    public static synchronized RevenueSourceFactory getInstance() {
        if (instance == null) {
            instance = new RevenueSourceFactory();
        }
        return instance;
    }
    
   /**
    * Gets the correct DAO based on the type of DAO that is queried
    * @return returns a RevenueSourceDAO based on the type parameter
    * @param type a string that indicates what type of DAO the user wants
    */
    public RevenueSourceDAO getDAO(String type){
        
        return (RevenueSourceDAO)map.get(type);
        
    }
}
